<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 卡牌分组 -->
    <script>
      var has = function (deck) {
        let map = new Map()
        for (let n of deck) {
          //统计频次
          map.set(n, map.has(n) ? map.get(n) + 1 : 1)
        }
        let arr = [...map.values()]
        let res = arr[0]
        return arr.every(i => (res = gcd(res, i)) > 1) //求最大公约数是否大于1
      }
      //辗转相除法 4,2
      let gcd = (a, b) => (b === 0 ? a : gcd(b, a % b))
      console.log(has([1, 2, 3, 4, 4, 3, 2, 1]))
    </script>
  </body>
</html>
